const adminDao = require("../dao/adminDao.js")

// 登录
module.exports.login = async function (account, password) {
    let data = await adminDao.findByUsername({ account })
    if (data.length > 0 && data[0].password == password) {
        return data;
    } else {
        return {};
    }
}
//注册
module.exports.register = async function (adminUser) {
    let data = await adminDao.findByUsername(adminUser)
    let result = data.filter(index=>index.account==adminUser.account)
    if (result.length) {
        return {}
    } else {
        return await adminDao.insert(adminUser)
    }
}
// 查找所有
module.exports.findAdminUser = async function (adminUser,page) {
    let data = await adminDao.findAdminUser(adminUser,page)
    return data;
}
module.exports.findUserAll = async function () {
    return await adminDao.findUserAll();
}
// 修改
module.exports.update = async function (id,adminUser) {
  let data =await adminDao.update(id,adminUser)
  return data 
}

//后台删除用户
module.exports.delete = async function(id){
    try {
        return await adminDao.delete(id)
    } catch (error) {
        return {}
    }
}

//根据ID查找
module.exports.findById=async function(id){
    try{
        return await adminDao.findById(id)
    }catch(e){
        return {}
    }
}